package com.sino.operation.config.swagger.bean;





import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;

import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Arrays;
import java.util.List;

/**
 * TOD
 *
 * @author Administrator
 * date 2021/9/14 0014 22:15
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
@ConditionalOnProperty(value = {"knife4j.enable"}, matchIfMissing = true)
public class SwaggerConfig {
    @Autowired
    private SwaggerProperties sp;

    @Bean
    public Docket getDocket(){

        ApiInfo apiInfo = apiInfo();
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        return docket.groupName("集中作业接口管理").pathMapping("/").apiInfo(apiInfo).select()
                .apis(RequestHandlerSelectors.basePackage(sp.getBasePackage()))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title(sp.getTitle())
                .description(sp.getDescription())
                .version(sp.getVersion())
                .contact(new Contact(sp.getContact().getName(),sp.getContact().getEmail(),sp.getContact().getEmail()))
                .build();
    }

}